﻿-- =============================================
-- Author:		<赵洪涛>
-- Create date: <2012-08-21>
-- Description:	<下发客户给OutSide>
-- =============================================
Create PROCEDURE [dbo].[proc_InOutSide_AllotOutSide]
(
	@CusId varchar(1000),
	@OutSide varchar(20),
	@IfP varchar(20)
)
AS
BEGIN
	Declare @cSql varchar(2000)
	DECLARE @DepId VARCHAR(30)
	
	SET SELECT @DepId=DepartmentId FROM employee WHERE UserName=@OutSide
	
	Set @cSql = 'Update InOutSide Set IfSide=''' + @IfP + ''',If_Date=GetDate(),OutSide=''' + @OutSide + ''',DepId='''+@DepId+'''
		Where Id In(' + @CusId + ')'
	Exec(@cSql)

	Set @cSql = 'Update Customer Set ProtectName=''' + @OutSide + ''' Where ProtectName = '''' And 
		CustomerId In(Select CusId From InOutSide Where Id In(' + @CusId + '))'
	Exec(@cSql)
END